home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE10 / CLINIC / GRIDSU.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-20  |  1.9 KB  |  82 lines

  1. unit Gridsu;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, DBGrids, DB, DBTables, ExtCtrls, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     DataSource1: TDataSource;
  12.     Table1: TTable;
  13.     DBGrid1: TDBGrid;
  14.     Table1CustNo: TFloatField;
  15.     Table1Company: TStringField;
  16.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  17.       Shift: TShiftState);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.DFM}
  30.  
  31. {$B-}
  32. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  33.   Shift: TShiftState);
  34.  
  35.   { Tabs are fine until we are at the last cell }
  36.   { Are we at the last tab stop ? }
  37.   function AtLastTabStop(G: TDBGrid): Boolean;
  38.   var
  39.     Loop: Word;
  40.   begin
  41.     Result := True;
  42.     with G do
  43.     begin
  44.       if SelectedIndex = Pred(FieldCount) then
  45.         Exit;
  46.       for Loop := Succ(SelectedIndex) to Pred(FieldCount) do
  47.       begin
  48.         Result := Fields[Loop].ReadOnly;
  49.         if not Result then
  50.           Exit;
  51.       end;
  52.     end;
  53.   end;
  54.  
  55.   procedure NextRecord(var Key: Word; DataSet: TDataSet);
  56.   begin
  57.     Key := 0;
  58.     if not DataSet.EOF then
  59.       DataSet.Next;
  60.   end;
  61.  
  62. begin
  63.   if (ActiveControl is TDBGrid) and
  64.      (TDBGrid(ActiveControl).DataSource <> nil) then
  65.     case Key of
  66.       vk_Tab: if not (ssShift in Shift) then
  67.         with TDBGrid(ActiveControl).DataSource, DataSet do
  68.           if AtLastTabStop(TDBGrid(ActiveControl)) then
  69.           begin
  70.             NextRecord(Key, DataSet);
  71.             if not EOF then
  72.               TDBGrid(ActiveControl).SelectedIndex := 0;
  73.           end;
  74.       vk_Down: if not (ssCtrl in Shift) then
  75.         with TDBGrid(ActiveControl).DataSource, DataSet do
  76.           NextRecord(Key, DataSet);
  77.       else Exit;
  78.     end;
  79. end;
  80.  
  81. end.
  82.